package com.youmingxing.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.youmingxing.R;
import com.youmingxing.view.clipheadphoto.clip1.msg.MessageCenter;
import com.youmingxing.view.clipheadphoto.clip1.msg.MessageTable;
import com.youmingxing.view.clipheadphoto.clip1.msg.MessageWithInt;

/**
 * A simple {@link Fragment} subclass.
 */
public class FocusFragment extends Fragment {

    private View view;
    private RelativeLayout focusLayout;

    public FocusFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_focus, container, false);

            FragmentManager manager = getFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();
            ContentListFragment focus = new ContentListFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("type", 3);
            focus.setArguments(bundle);

            transaction.replace(R.id.focus_fragment, focus);
            transaction.commitAllowingStateLoss();
        }
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (view != null) {
            ((ViewGroup) view.getParent()).removeView(view);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        MessageWithInt msgToSend1 = new MessageWithInt();
        msgToSend1.setMsgId(MessageTable.RefreshNews3);
        msgToSend1.setInt(3);
        MessageCenter.getInstance().sendMessage(msgToSend1);
    }
}
